package Tools;

import com.fs.zise.GameMap;
import com.fs.zise.ZiSeActivity;

import Appconst.GameConst;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.widget.Toast;

public class GameWordButton extends GameButton implements android.view.GestureDetector.OnGestureListener{

	public final static int WordButtonFlag_Tutorial[] = {1000};
	 private JTextUtil jTextUtil = new JTextUtil();
//	 private int offx_wordBGBUTTON;//文字相对于 文字背景图片X 偏移量
//	 private int offy_wordBGBUTTON;//文字相对于 文字背景图片Y 偏移量
	 private String title; //需要在背景图片上显示的标题
	 private String content; //需要在背景图片上显示的对应于标题的内容
	 private float RawX;
	 private float RawY;

	 
	public GameWordButton(int id, Bitmap bg, int x, int y, int w,
			int h,String title,String content) {
		super(id, bg, x, y, w, h);
		
		this.title = title;
		this.content = content;
		
		System.out.println("GameWordButton.GameWordButton()---HH ="+h);
		
		setVisible(true);
		setScaleBgW(GameConst.SCR_W);
		
		if(GameMap.getSingleInstance().getLevel() == 0)
			jTextUtil.InitText(content, x+20, y+70, (int)getScaleBgW()-40, h-80, 0, 255, 32);
		
	}
	

	@Override
	public void onDraw(Canvas canvas, Paint paint) {
		
		if(getVisible())
		{
		super.onDraw(canvas, paint);
		//绘制标题
		JTextUtil.drawLable(title, canvas, paint,getWidth()/3, getY(), getWidth(),getHeight()/4, 0xaeff0000, 32, true);
		//绘制内容
		jTextUtil.DrawText(canvas);
		}
	}

	@Override
	public boolean OnButtonPressed(float touchX, float touchY) {
		if(!getVisible())
			return false;
		
		
		if(super.OnButtonPressed(touchX, touchY))
		{
			RawX  = touchX ;
			RawY  = touchY;
			return true;
		}
		else
			return false;
			
	}
	
	@Override
	public boolean OnButtonMoved(float touchX, float touchY) {
		
		if(!getVisible())
			return false;
		
		boolean up = false;
		boolean down = false;
		 if(touchY - RawY > 32)
			down = true;
		else if(touchY - RawY < -32)
			up = true;
		
		if(up)
		{
			jTextUtil.PageUp(false);
			RawX  = touchX;
			RawY = touchY;
		}
		else if(down)
		{
			jTextUtil.PageUp(true);
			RawX  = touchX;
			RawY = touchY;
		}
		
			
		return true;
	}
	
	@Override
	public boolean OnButtonLeaved(float touchX, float touchY) {
		if(!getVisible())
			return false;
		
		if(touchX>getScaleBgW()-40&&touchY>getY()&&touchX<getScaleBgW()&&touchY<getY()+40)
			setVisible(false);
		
		return true;
	}
	
	@Override
	public boolean onDown(MotionEvent e) {
		// TODO Auto-generated method stub
		 Toast.makeText(ZiSeActivity.getActivity(), "按下操作", Toast.LENGTH_SHORT).show();
		 
		return false;
	}

	
	
	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		
		if(e1 == null)
			return false;
		
		 final int FLING_MIN_DISTANCE=100;//X或者y轴上移动的距离(像素)      
		 final int FLING_MIN_VELOCITY=200;//x或者y轴上的移动速度(像素/秒)        
		 if((e1.getX()-e2.getX())>FLING_MIN_DISTANCE && Math.abs(velocityX)>FLING_MIN_VELOCITY)    
		 {
			 Toast.makeText(ZiSeActivity.getActivity(), "快速移动向左滑动", Toast.LENGTH_SHORT).show();
		 }
		 else if((e2.getX()-e1.getX())>FLING_MIN_DISTANCE && Math.abs(velocityX)>FLING_MIN_VELOCITY)     
			 Toast.makeText(ZiSeActivity.getActivity(), "快速移动向右滑动", Toast.LENGTH_SHORT).show();
		 if((e1.getY()-e2.getY())>FLING_MIN_DISTANCE && Math.abs(velocityY)>FLING_MIN_VELOCITY)    
		 {
//			 jTextUtil.PageUp(false);
			 Toast.makeText(ZiSeActivity.getActivity(), "快速移动向上滑动", Toast.LENGTH_SHORT).show();
			 
		 }
		 else if((e2.getY()-e1.getY())>FLING_MIN_DISTANCE && Math.abs(velocityY)>FLING_MIN_VELOCITY)    
		 {
//			 jTextUtil.PageUp(true);
			 Toast.makeText(ZiSeActivity.getActivity(), "快速移动向下滑动", Toast.LENGTH_SHORT).show();
		 }
		
		return false;
	}

	@Override
	public void onLongPress(MotionEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {
//		 Toast.makeText(ZiSeActivity.getActivity(), "滑动。。。", Toast.LENGTH_SHORT).show();
		System.out.println("distanceY  ="+distanceY);
//		if(distanceY*10>-30)
//		{
//			System.out.println("wwwwww");
//			 jTextUtil.PageUp(true);
//		}
//		else if(distanceY*10>-30)
//		{
//			jTextUtil.PageUp(true);
//		}
		return false;
	}

	@Override
	public void onShowPress(MotionEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}

}
